<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: datetimepicker-css" />
    <script src="http://192.168.10.101:18000/CLodopfuncs.js?priority=0"></script>
    <script src="http://192.168.10.101:8000/CLodopfuncs.js?priority=1"></script>
    <script language="javascript" src="http://192.168.10.101:8000/LodopFuncs.js"></script>
    <script src='http://192.168.10.101:8000/CLodopfuncs.js'></script>
</head>
<style type="text/css">
    .table {
        table-layout: fixed;
    }</style>
<body class="gray-bg">



<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="operlog-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>检索：</label><input type="text" name="sbbh" id="sbbh" placeholder="请输入设备编码进行查询"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search_btn"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>


<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-select-js"/>
<th:block th:include="include :: jasny-bootstrap-js" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var selections = [];
    var LODOP; //声明为全局变量
    var now = getNow();
    watermark({"watermark_txt": "A B C X Y Z " + now});
    $(document).ready(function () {
        initUserTable();
        function initUserTable() {
            $("#bootstrap-table").bootstrapTable({
                toolbar: '#toolbar',
                showToggle: true,//是否切换显示
                showColumns: true,//是否显示列，
                showColumnsToggleAll: true,
                detailView: true,//和下面的属性成对设置，是否显示加号显示详细信息
                detailFormatter: "detailFormatter",
                showExport: true,//是否导出
                // showPaginationSwitch: true,//切换是否分页显示
                showFooter: true,//是否显示页脚，主要用途是显示汇总的信息
                striped: false,//是否显示行间隔色
                paginationPreText: '上一页',
                paginationNextText: '下一页',
                queryParamsType: '',
                method: 'GET',
                uniqueId: "id",

                pageNumber: 1,
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 10,//单页记录数
                pageList: [10, 20, 30, 'ALL'],//可选择单页记录数
                showRefresh: true,//刷新按钮
                queryParams: queryParams,
                // onDblClickRow: function (row,index) {
                //     console.log(index[0])
                // },
                onDblClickRow:function(row,tr,flied){
                    tr.addClass("selected")
                    alert(row.id)
                    tr.attr("checked",true)
                },

                url: "/nc/sysSpcrkls/getspcrklsall/",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'no',
                        title: '序号',
                        align: "center",
                        width: 60,
                        formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize=$('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                            //获取当前是第几页
                            var pageNumber=$('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;}
                    },
                    {
                        field: '单据日期',
                        title: '单据日期'
                    },
                    {
                        field: '商品名称',
                        title: '商品名称'
                    },
                    {
                        field: '商品规格',
                        title: '商品规格',
                        // sortable: true,
                    },
                    {
                        field: '生产企业',
                        title: '生产企业'
                    },
                    {
                        field: '批号',
                        title: '批号'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            // var actions = [];
                            // actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="updatetjmtk(row.id)" data-toggle="modal" data-target="#myModal5"><i class="fa fa-edit"></i>编辑</a> ');
                            // actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            // // actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="resetPwd(\'' + row.userId + '\')"><i class="fa fa-key"></i>重置</a>');
                            // return actions.join('');
                            var id = index;
                            var data = JSON.stringify(row);
                            var result = "";
                            result += "<a href='javascript:;' class='btn btn-xs green' onclick=\"ViewById('" + id + "')\" title='查看'><span class='glyphicon glyphicon-search'></span></a>";
                            result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"EditViewById('" + row + "','" + id + "')\" title='生成二维码'><span class='glyphicon glyphicon-pencil'></span></a>";
                            result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DeleteByIds('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
                            return result;
                        }
                    }]
            })
        }
    });

    //查询按钮事件
    $('#search_btn').click(function () {
        $('#bootstrap-table').bootstrapTable('refresh', {
            url: '/nc/sbxxb/getsblist/' + $('#sbbh').val(),
        });
    });

    $('#creat_sbbh_btn').click(function () {
        var sb = $("#sbbh_sel option:selected").val();
        var sbmc = $("#sbbh_sel option:selected").text();
        var sbbh = "";
        $.ajax({
            url: "/nc/sbxxb/maxsbbh/" + sb,
            type: 'GET',
            success: function (data) {
                sbbh = sb + (parseInt(data) + 1);
                $("#sbbh_id").val(sbbh);
                $("#sbmc_id").val(sbmc);
            },
        })
    });

    $("#button-open-4").click(function () {
        $.modal.open('添加用户', "/form", '900', '500', callback);
    })

    function callback(index, layero) {
        alert("进入了回调函数提交方法");
        $.ajax({
            url: "/nc/sysNc/insertspkfk",
            type: 'POST',
            data: $("#form-user-add form").serialize(),
            success: function (result) {
                if (result != null) {
                    alert("添加商品成功！！！");
                }
            }
        });
    }

    function getIdSelections() {
        return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
            return row.id
        })
    }

    function getsbbhSelections() {
        return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
            return row.sbbh
        })
    }

    //多个删除
    function remove() {
        var ids = getIdSelections();
        var wents = getwentSelections();
        if (confirm("确认删除【" + wents + "】吗？？？")) {
            $.ajax({
                url: "/nc/sysNc/deleteallspkfk/" + ids,
                type: 'DELETE',
                success: function (result) {
                    if (result != null) {
                        alert("删除成功！！！");
                        window.location.href = window.location.href;
                    }
                },
            });
        }
    }
    function responseHandler(res) {

        $.each(res.rows, function (i, row) {
            row.state = $.inArray(row.id, selections) !== -1
        })
        return res
    }
    function queryParams(params) {
        var param = {
            limit: params.limit, // 页面大小
            offset: params.offset, // 页码
            nextPage: params.pageNumber,
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            // sbbh: $("#sbbh").val(),
        };
        return param;
    }

    function detailFormatter(index, row) {
        var html = []
        $.each(row, function (key, value) {
            html.push('<p><b>' + key + ':</b> ' + value + '</p>')
        })
        return html.join('')
    }

    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width: 100,
        height: 100
    });
    //打印设备台账开始
    function Mysbtz() {
        var options = $('#divid_sbtz').html();
        LODOP = getLodop();
        LODOP.PRINT_INIT("");
        LODOP.ADD_PRINT_TABLE(5, 5, 2970, 2100, options);
        LODOP.PREVIEW();
    };
    //打印设备台账结束
    //生成二维码js开始
    function EditViewById(row, index) {
        //$('.edittosummernote').summernote('destroy');
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data); //data_json和data_json2一样都是json对象
        var data_json2 = eval("(" + data + ")");
        $('#text').val('http://192.168.10.101:9090/nc/sbxxb/sbwh/' + data_json[index].sbbh + '/');
        // //由于data2已经是对象了，alert不能显示对象只能显示为[object Object],需要控制台打印
        // //根据index找到对应行数据，填充数据到修改模态框
        // $("#id_update_static_15").val(data_json[index].id);
        // $("#mkmc_update_input_15").val(data_json[index].mkmc);
        // $("#went_update_input_15").val(data_json[index].went);
        // $("#yuany_update_input_15").val(data_json[index].yuany);
        // // $("#jjbz_update_input_15").val(data_json[index].jjbz);
        //
        // $('.edittosummernote').html($(".edittosummernote").val(data_json[index].jjbz).val());
        // $('.edittosummernote').summernote({focus: true});
        // $("#emp_update_btn").val(data_json[index].id);
        // //弹出修改模态框，非新增模态框
        // $('#myModal5').modal('show')

        // $('.edittosummernote').html($('#text').val('http://localhost:9090/nc/sbxxb/sbxx/' + data_json[index].sbbh));
        // $('.edittosummernote').summernote({好，那我们来我看下啊，55 15 15。那我想问一下。是？
        //     callbacks: {
        //         onInit: function () {
        //             var elText = document.getElementById("text");
        //             qrcode.makeCode(elText.value);
        //             // alert(window.screenY);
        //         }
        //     }
        // });

        $("#emp_save_btn").val(data_json[index].sbbh);
        makecode();
        $('#empAddModal').modal('show');
    }
    function makecode() {
        var elText = document.getElementById("text");
        qrcode.makeCode(elText.value);
        // alert(document.getElementById("qrcode").lastElementChild.outerHTML);
    }
    //生成二维码js结束
    function updatespkfk(obj) {
        var sbbh = obj.getAttribute("value");
        var qrcode = document.getElementById("qrcode").lastElementChild.outerHTML;
        $("#qrcode_update_input_15").val(qrcode);
        $.ajax({
            url: "/nc/sbxxb/editspkfk/" + sbbh,
            type: 'PUT',
            data: $("#empAddModal form").serialize(),
            success: function (result) {
                if (result != null) {
                    $("#empAddModal").modal('hide');
                    window.location.href = window.location.href;
                }
            }
        });
    };
    //打印设备标签二维码开始
    function MyPreview() {
        var column = $('#bootstrap-table').bootstrapTable('getSelections');
        var options = "";
        LODOP = getLodop();
        LODOP.PRINT_INIT("");
        var iCurLine = 20;
        for (var i = 0; i < column.length; i++) {  //遍历json数组
            options = "<table class='table table-hover table-bordered' cellpadding='0' border='1' cellspacing='0'>"
                + "<tr><td colspan='2'><div align='center' style='font-family: 微软雅黑;font-size: 14pt'>安徽海王国安医药有限公司</div></td><td rowspan='4'>" + column[i].qrcode + "</td></tr>"
                + "<tr><td colspan='2'><div align='center' style='font-size: 14pt;font-family: 微软雅黑'>固定资产管理标签</div></td></tr>"
                + "<tr><td><div align='center' style='font-family: 微软雅黑;font-size: 14pt'>资产编号</div></td><td><div align='center'><strong style='font-size: 18pt;font-family: 微软雅黑'>" + column[i].sbbh + "</strong></div></td></tr>"
                + "<tr><td><div align='center' style='font-size: 14pt;font-family: 微软雅黑'>资产名称</div></td><td><div align='center'><strong style='font-family: 微软雅黑;font-size: 18pt'>" + column[i].sbmc + "</strong></div></td></tr>"
                + "</table>";
            if (i % 2 == 1) {
                LODOP.ADD_PRINT_TABLE(iCurLine, 410, 380, 20, options);
                iCurLine += 130;
            } else {
                LODOP.ADD_PRINT_TABLE(iCurLine, 20, 380, 20, options);
            }
        }
        // $('#divid').append(options);
        LODOP.PREVIEW();
    };
    //打印设备标签二维码开始
    function gettjmtk() {
        $("#sbAddModal").modal({
            backdrop: "static"
        });
        getDepts("#sbAddModal select");
    };
    $(function () {
        layui.use('laydate',function () {
            var laydate=layui.laydate;
            laydate.render({
                elem:'#gmrq_id',
                type:'date'
            });
        });
    });
    function getDepts(ele) {
        $.ajax({
            url: "/nc/bmxxb/getbmxx/",
            type: 'get',
            success: function (data) {
                $('#bmid_id').empty();
                var options = "";   //字符串拼接
                $("#bmid_id").append('<option value="">请选择部门</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].id + "'>" + data[i].bmmc + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#bmid_id').append(options);
            },
        });
    };
    $('#bmid_id').change(function () {
        var bmid = $("#bmid_id option:selected").val();
        $.ajax({
            url: "/nc/ygxxb/getygxx/"+ bmid,
            type: 'get',
            success:function (data) {
                $('#shiyr_id').empty();
                var options = "";   //字符串拼接
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].id + "'>" + data[i].xingm + "</option>"
                }
                $('#shiyr_id').append(options);
            },
        });
    });


    function savesb() {
        alert($("#sbAddModal form").serialize())
        $.ajax({
            url: "/nc/sbxxb/insertsb",
            type: 'POST',
            data: $("#sbAddModal form").serialize(),
            success: function (result) {
                if (result != null) {
                    alert("添加成功！！！");
                    $("#sbAddModal").modal('hide');
                    window.location.href = window.location.href;
                }
            }
        });
    }
</script>
</body>
</html>